<?php
namespace Amis\functions;

use Amis\Basics\AmisBasics;

class Service extends AmisBasics
{
    public string $type = 'service';


    public function className($className)
    {
        $this->className = $className;
        return $this;
    }

    public function body($body)
    {
        $this->body = $body;
        return $this;
    }

    public function api(string $apiUrl)
    {
        $this->api = $apiUrl;
        return $this;
    }

    public function ws(string $wsUrl)
    {
        $this->ws = $wsUrl;
        return $this;
    }

    public function dataProvider(string $dataProvider)
    {
        $this->dataProvider = $dataProvider;
        return $this;
    }

    public function initFetch(bool $initFetch)
    {
        $this->initFetch = $initFetch;
        return $this;
    }

    public function schemaApi(string $schemaApi)
    {
        $this->schemaApi = $schemaApi;
        return $this;
    }

    public function initFetchSchema(bool $initFetchSchema)
    {
        $this->initFetchSchema = $initFetchSchema;
        return $this;
    }

    /**
     * messages.fetchSuccess    string        接口请求成功时的 toast 提示文字
     * messages.fetchFailed       string       "初始化失败"    接口请求失败时 toast 提示文字
     * @param $messages
     * @return $this
     */
    public function messages($messages)
    {
        $this->messages = $messages;
        return $this;
    }

    public function interval(int $interval)
    {
        $this->interval = $interval;
        return $this;
    }

    public function silentPolling(bool $silentPolling = false)
    {
        $this->silentPolling = $silentPolling;
        return $this;
    }

    /**
     * 配置停止轮询的条件
     * @param string $stopAutoRefreshWhen
     * @return $this
     */
    public function stopAutoRefreshWhen(string $stopAutoRefreshWhen = '')
    {
        $this->stopAutoRefreshWhen = $stopAutoRefreshWhen;
        return $this;
    }
}